<template>
  <a-modal :visible="true" :footer="null" :width="500" @cancel="cancelEvent" class="orderModal">
    <div class="infoModal">角色权限</div>
    <a-tree style="margin:0 30px" :show-line="true" 
    v-model="checkedKeys" checkable 
    :expanded-keys="expandedKeys" :auto-expand-parent="autoExpandParent" 
    :tree-data="treeData" @expand="onExpand" @select="onSelect" />
    <div style="height:20px;width:100%"></div>
  </a-modal>

</template>
<script>
export default {
  props: ['roleType'],
  data() {
    return {
      expandedKeys: ['0-0-0','0-1-0','0-1-1','0-1-2','0-1-3','0-2-0','0-2-1','0-2-2','0-3-0','0-3-1',
      '0-3-2','0-3-3','0-3-4','0-3-5','0-3-6','0-3-7','0-3-8','0-3-9','0-3-10','0-3-11','0-3-12','0-3-13','0-3-14',
      '0-3-15','0-3-16','0-3-17','0-4-0','0-5-0','0-5-1'],
      expandedKeys2: ['0-0-0','0-1-0','0-1-1','0-1-2','0-1-3','0-2-0','0-2-1'],
      expandedKeys3: ['0-0-0','0-3-0','0-3-1','0-3-2','0-3-3','0-3-4','0-3-5','0-3-6','0-3-7','0-3-8','0-3-9'],
      expandedKeys4: ['0-0-0','0-3-0','0-3-1','0-3-2','0-3-3','0-3-4','0-3-5','0-3-6','0-3-7','0-3-8','0-3-9','0-3-10','0-3-11','0-3-12','0-3-13','0-3-14',
      '0-3-15','0-3-16','0-3-17'],
      autoExpandParent: true,
      checkedKeys: ['0-0-0','0-1-0','0-1-1','0-1-2','0-1-3','0-2-0','0-2-1','0-2-2','0-3-0','0-3-1',
      '0-3-2','0-3-3','0-3-4','0-3-5','0-3-6','0-3-7','0-3-8','0-3-9','0-3-10','0-3-11','0-3-12','0-3-13','0-3-14',
      '0-3-15','0-3-16','0-3-17','0-4-0','0-5-0','0-5-1'],
      treeData: '',
      treeData1,
      treeData2,
      treeData3,
      treeData4,
      treeData5,
      treeData6,
      type:1
    }
  },
  watch: {
    checkedKeys(val) {
      console.log('onCheck', val)
    },
  },
  created() {
    //此处赋值各个角色的权限列表
    this.treeData = this.getUserRight(this.roleType)//treeData2 treeData3 treeData4 treeData5 treeData6
   
  },
  methods: {
    cancelEvent() {
      this.$emit('cancelEvent')
    },
    getUserRight(role) {
      let userRightList = []
      switch (role) {
        case '超级管理员' || '管理员':
          userRightList = this.treeData1
          this.expandedKeys =  this.expandedKeys
          this.checkedKeys = this.expandedKeys
          break
        case '客户经理':
          userRightList = this.treeData2
          this.expandedKeys =  this.expandedKeys2
          this.checkedKeys = this.expandedKeys2
          
          break
        case '项目经理':
          userRightList = this.treeData3
          this.expandedKeys =  this.expandedKeys2
          this.checkedKeys = this.expandedKeys2
          break
        case '代维单位':
          userRightList = this.treeData4
          this.expandedKeys =  this.expandedKeys3
          this.checkedKeys = this.expandedKeys3
          break
        case '区县公司':
          userRightList = this.treeData5
          this.expandedKeys =  this.expandedKeys3
          this.checkedKeys = this.expandedKeys3
          break
        case '市公司':
          userRightList = this.treeData6
          this.expandedKeys =  this.expandedKeys4
          this.checkedKeys = this.expandedKeys4
          break
        default:
          userRightList = this.treeData1
          this.expandedKeys =  this.expandedKeys
          this.checkedKeys = this.expandedKeys
      }

      return userRightList
    },
    onExpand(expandedKeys) {
      // 点击切换
      this.expandedKeys = expandedKeys
      this.autoExpandParent = false
    },
    onCheck(checkedKeys) {
      console.log('onCheck', checkedKeys)
      this.checkedKeys = checkedKeys
    },
    onSelect(selectedKeys, info) {
      console.log('onSelect', info)
      this.selectedKeys = selectedKeys
    },
  },
}
//超级管理员
const treeData1 = [
  {
    title: '首页',
    key: '0-0-0',
    disableCheckbox: true,
  },
  {
    title: '指标分析',
    key: '0-1-0',
    hidden:true,
    disableCheckbox: true,
    children: [
      { title: '开通', key: '0-1-1', disableCheckbox: true },
      { title: '故障', key: '0-1-2', disableCheckbox: true },
      { title: '报表', key: '0-1-3', disableCheckbox: true },
    ],
  },
  {
    title: '催办管理',
    key: '0-2-0',
    disableCheckbox: true,
    children: [
      { title: '报表', key: '0-2-1', disableCheckbox: true },
      { title: '工单进度操作', key: '0-2-2', disableCheckbox: true },
    ],
  },
  {
    title: '账户管理',
    key: '0-4-0',
    disableCheckbox: true,
  },
  ,
  {
    title: '资源管理',
    key: '0-3-0',
    disableCheckbox: true,
    children: [
      {
        title: '视频管理',
        key: '0-3-1',
        disableCheckbox: true,
        children: [
          {
            title: '维护资源',
            key: '0-3-2',
            disableCheckbox: true,
            children: [
              { title: '资源入口', key: '0-3-3', disableCheckbox: true },
              { title: '资源录入', key: '0-3-4', disableCheckbox: true },
              {
                title: '资源统计',
                key: '0-3-5',
                disableCheckbox: true,
                children: [
                  { title: '站点统计', key: '0-3-6', disableCheckbox: true },
                  { title: '站点导出', key: '0-3-7', disableCheckbox: true },
                ],
              },
            ],
          },
          {
            title: '待维资源管理',
            key: '0-3-8',
            disableCheckbox: true,
            children: [
              { title: '合同管理', key: '0-3-9', disableCheckbox: true },
              {
                title: '物资管理',
                key: '0-3-10',
                disableCheckbox: true,
                children: [
                  { title: '新增管理', key: '0-3-11', disableCheckbox: true },
                  { title: '统计管理', key: '0-3-12', disableCheckbox: true },
                  { title: '配置设置', key: '0-3-13', disableCheckbox: true },
                ],
              },
            ],
          },
          {
            title: '巡检管理',
            key: '0-3-14',
            disableCheckbox: true,
            children: [
              { title: '巡检报告', key: '0-3-15', disableCheckbox: true },
              { title: '巡检统计', key: '0-3-16', disableCheckbox: true },
            ],
          },
          { title: '费用管理', key: '0-3-17', disableCheckbox: true },
        ],
      },
    ],
  },
  {
    title: '系统配置',
    key: '0-5-0',
    disableCheckbox: true,
    children: [{ title: '数据导入', key: '0-5-1', disableCheckbox: true }],
  },
]
//客户经理
const treeData2 = [
  {
    title: '首页',
    key: '0-0-0',
    disableCheckbox: true,
  },
  {
    title: '指标分析',
    key: '0-1-0',
    disableCheckbox: true,
    children: [
      { title: '开通', key: '0-1-1', disableCheckbox: true },
      { title: '故障', key: '0-1-2', disableCheckbox: true },
      { title: '报表', key: '0-1-3', disableCheckbox: true },
    ],
  },
  {
    title: '催办管理',
    key: '0-2-0',
    disableCheckbox: true,
    children: [
      { title: '报表', key: '0-2-1', disableCheckbox: true },
      // { title: '工单进度操作', key: '0-0-1-1' ,disableCheckbox: true}
    ],
  },
]
//项目经理
const treeData3 = [
  {
    title: '首页',
    key: '0-0-0',
    disableCheckbox: true,
  },
  {
    title: '指标分析',
    key: '0-1-0',
    disableCheckbox: true,
    children: [
      { title: '开通', key: '0-1-1', disableCheckbox: true },
      { title: '故障', key: '0-1-2', disableCheckbox: true },
      { title: '报表', key: '0-1-3', disableCheckbox: true },
    ],
  },
  {
    title: '催办管理',
    key: '0-2-0',
    disableCheckbox: true,
    children: [
      { title: '报表', key: '0-2-1', disableCheckbox: true },
      // { title: '工单进度操作', key: '0-2-2', disableCheckbox: true },
    ],
  },
]
//代维单位
const treeData4 = [
  {
    title: '首页',
    key: '0-0-0',
    disableCheckbox: true,
  },
  {
    title: '资源管理',
    key: '0-3-0',
    disableCheckbox: true,
    children: [
      {
        title: '视频管理',
        key: '0-3-1',
        disableCheckbox: true,
        children: [
          {
            title: '维护资源',
            key: '0-3-2',
            disableCheckbox: true,
            children: [
              { title: '资源入口', key: '0-3-3', disableCheckbox: true },
              { title: '资源录入', key: '0-3-4', disableCheckbox: true },
              { title: '资源统计', key: '0-3-5', disableCheckbox: true,
                children: [
                  { title: '站点统计', key: '0-3-6', disableCheckbox: true },
                  //  { title: '站点导出', key: '1',disableCheckbox: true},
                ],
              },
            ],
          },
          {
            title: '巡检管理',
            key: '0-3-7',
            disableCheckbox: true,
            children: [
              { title: '巡检报告', key: '0-3-8', disableCheckbox: true },
              { title: '巡检统计', key: '0-3-9', disableCheckbox: true },
            ],
          },
        ],
      },
    ],
  },
]
//区县公司
const treeData5 = [
  {
    title: '首页',
    key: '0-0-0',
    disableCheckbox: true,
  },
  {
    title: '资源管理',
    key: '0-3-0',
    disableCheckbox: true,
    children: [
      {
        title: '视频管理',
        key: '0-3-1',
        disableCheckbox: true,
        children: [
          {
            title: '维护资源',
            key: '0-3-2',
            disableCheckbox: true,
            children: [
              { title: '资源入口', key: '0-3-3', disableCheckbox: true },
              { title: '资源录入', key: '0-3-4', disableCheckbox: true },
              { title: '资源统计', key: '0-3-5', disableCheckbox: true,
                children: [
                  { title: '站点统计', key: '0-3-6', disableCheckbox: true },
                  //  { title: '站点导出', key: '1',disableCheckbox: true},
                ],
              },
            ],
          },
          {
            title: '巡检管理',
            key: '0-3-7',
            disableCheckbox: true,
            children: [
              { title: '巡检报告', key: '0-3-8', disableCheckbox: true },
              { title: '巡检统计', key: '0-3-9', disableCheckbox: true },
            ],
          },
        ],
      },
    ],
  },
]
//市公司
const treeData6 = [
  {
    title: '首页',
    key: '0-0-0',
    disableCheckbox: true,
  },
  {
    title: '资源管理',
    key: '0-3-0',
    disableCheckbox: true,
    children: [
      {
        title: '视频管理',
        key: '0-3-1',
        disableCheckbox: true,
        children: [
          {
            title: '维护资源',
            key: '0-3-2',
            disableCheckbox: true,
            children: [
              { title: '资源入口', key: '0-3-3', disableCheckbox: true },
              { title: '资源录入', key: '0-3-4', disableCheckbox: true },
              {
                title: '资源统计',
                key: '0-3-5',
                disableCheckbox: true,
                children: [
                  { title: '站点统计', key: '0-3-6', disableCheckbox: true },
                  { title: '站点导出', key: '0-3-7', disableCheckbox: true },
                ],
              },
            ],
          },
          {
            title: '待维资源管理',
            key: '0-3-8',
            disableCheckbox: true,
            children: [
              { title: '合同管理', key: '0-3-9', disableCheckbox: true },
              {
                title: '物资管理',
                key: '0-3-10',
                disableCheckbox: true,
                children: [
                  { title: '新增管理', key: '0-3-11', disableCheckbox: true },
                  { title: '统计管理', key: '0-3-12', disableCheckbox: true },
                  { title: '配置设置', key: '0-3-13', disableCheckbox: true },
                ],
              },
            ],
          },
          {
            title: '巡检管理',
            key: '0-3-14',
            disableCheckbox: true,
            children: [
              { title: '巡检报告', key: '0-3-15', disableCheckbox: true },
              { title: '巡检统计', key: '0-3-16', disableCheckbox: true },
            ],
          },
          { title: '费用管理', key: '0-3-17', disableCheckbox: true },
        ],
      },
    ],
  },
]
</script>
<style lang="less">
.infoModal {
  height: 51px;
  background: rgba(255, 255, 255, 1);
  border-radius: 6px 6px 0px 0px;
  text-align: center;
  line-height: 51px;
  font-size: 18px;
  font-family: PingFang SC;
  font-weight: bold;
  color: rgba(0, 0, 0, 1);
}
</style>